#include "mailwidget.h"
#include <QSplitter>
#include <QHBoxLayout>
#include <QDebug>
#include <QList>
#include <QTreeWidgetItem>

MailWidget::MailWidget(QWidget *parent) :
    QWidget(parent)
{
    tableWidget = new QTableWidget(this);
    treeWidget = new QTreeWidget(this);
    textEdit = new QTextEdit(this);

    treeWidget->setColumnCount(1);
    treeWidget->setHeaderLabel(tr("Option"));
    QList<QTreeWidgetItem* > items;

    for (int i = 0; i < 10; ++i){
        items.append(new QTreeWidgetItem(
                         QStringList(QString("item: %1").arg(i))));
    }
    treeWidget->insertTopLevelItems(0, items);

    QList<QTreeWidgetItem *>::iterator iter = items.begin();
    while(iter != items.end()){
        (*iter)->addChild(new QTreeWidgetItem(QStringList(QString("one item"))));
        ++iter;
    }

    QSplitter *rightSplitter = new QSplitter(Qt::Vertical);
    rightSplitter->addWidget(tableWidget);
    rightSplitter->addWidget(textEdit);
    rightSplitter->setStretchFactor(1, 1);

    QSplitter *mainSplitter = new QSplitter(Qt::Horizontal);
    mainSplitter->addWidget(treeWidget);
    mainSplitter->addWidget(rightSplitter);
    mainSplitter->setStretchFactor(1, 1);

    QHBoxLayout *mainLayout = new QHBoxLayout;
    mainLayout->addWidget(mainSplitter);
    setWindowTitle("Mail Client");

    setLayout(mainLayout);
}
